var gulp = require('gulp');
var jshint = require('gulp-jshint');
var uglify = require('gulp-uglify');
var concat = require('gulp-concat');
var sass = require('gulp-sass');
var cleanCSS = require('gulp-clean-css');
var autoprefixer = require('gulp-autoprefixer');

var jsList = [
  'vendor/vue.min.js',
  'vendor/jquery.js',
  'vendor/fullPage/dist/jquery.fullpage.js',
  'vendor/swiper/dist/js/swiper.js',
  'vendor/lodash.js',
  'vendor/jquery.nav.js',
  'vendor/element/index.js'
]

var cssList = [
  'vendor/normalize.css',
  'vendor/animate.css',
  'vendor/fullPage/dist/jquery.fullpage.css',
  'vendor/swiper/dist/css/swiper.css',
  'vendor/element/index.css',
  'src/css/style.css'
]

gulp.task('default', ['js', 'scss', 'concatstyle']);

gulp.task('js', function () {
  return gulp.src(jsList)
    .pipe(jshint.reporter('default'))
    .pipe(concat('bundle.js'))
    .pipe(uglify())
    .pipe(gulp.dest('dist'));
});

gulp.task('scss', function () {
  return gulp.src('src/scss/style.scss')
    .pipe(sass().on('error', sass.logError))
    .pipe(gulp.dest('src/css'));
});

gulp.task('concatstyle', ['scss'], function () {
  return gulp.src(cssList)
    .pipe(concat('style.css'))
    .pipe(autoprefixer({
      browsers: ['last 2 versions']
    }))
    .pipe(cleanCSS())
    .pipe(gulp.dest('dist'));
})

gulp.task('watch', function () {
  gulp.watch('src/scss/*.scss', ['scss', 'concatstyle']);
});